<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Common\Library\COM;

/**
 * Description of SEODo
 *
 * @author gangguo
 */
class SeoDo {
    //put your code here

    //章节名称中获取文章章节数
    static public function baiduSeo($urls = ''){
        // $urls = array(
        //     'http://www.example.com/1.html',
        //     'http://www.example.com/2.html',
        // );
        if(!is_array($urls)){
            return false;
        }
        $api = 'http://data.zz.baidu.com/urls?site=www.896zw.com&token=AJcyuOvJuAHB8Dwy';
        $ch = curl_init();
        $options =  array(
            CURLOPT_URL => $api,
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS => implode("\n", $urls),
            CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
        );
        curl_setopt_array($ch, $options);
        $result = curl_exec($ch);
        echo $result;
    }


    static public function siteMap($urls='',$pathFile = './sitemap_896zw.xml'){
        if(!is_array($urls)){
            return false;
        }
        $str = '<?xml version="1.0" encoding="utf-8"?><urlset>';
        foreach ($urls as $key => $value) {
            # code...
            $str .='<url>';
            $str .= '<loc>'.$value['loc'].'</loc>';
            $str .= '<lastmod>'.$value['lastmod'].'</lastmod>';
            $str .= '<changefreq>'.$value['changefreq'].'</changefreq>';
            $str .= '<priority>'.$value['priority'].'</priority>';
            $str .='</url>';
        }
        $str .= '</urlset>';
        $length = file_put_contents($pathFile, $str);
        if(empty($length)){
            return false;
        }
        return true;
    }





}
